{php}
    // 获取一级联动数据
    $levelOne  = getLinkageData($form[type]['model'], 0, $form[type]['pid']);
    $levelKey  = [];
    $levelData = [];

    // 默认值
    if ($form[type]['value'] != '') {
        $levelKeyData = getLinkageAllData($form[type]['model'], $form[type]['value'], $form[type]['key'], $form[type]['option'], $form[type]['pid']);
        $levelKey = $levelKeyData['key'];
        $levelData = $levelKeyData['data'];
        sort($levelKey); // 升序排序
        $levelData = array_reverse($levelData); // 以相反的元素顺序返回数组
    }
{/php}
<div class="row dd_input_group no-gutters {$form[type].extra_class|default=''}" id="form_group_{$form[type].name}">
    <label class="col-3 col-sm-2 col-md-2 col-lg-2 col-xl-1 dd_input_l col-form-label {notempty name="form[type].required"}is-required{/notempty}" for="{$form[type].name}">{$form[type].title|htmlspecialchars}</label>
    <div class="col-9 col-sm-9 col-md-9 col-lg-8 col-xl-7">
        <select class="form-control js_linkage" data-model="{$form[type]['model']}" data-key="{$form[type]['key']}" data-key_value="{$form[type]['option']}" data-pid_field_name="{$form[type].pid|default='pid'}" data-next_level_id="{$form[type].name}_2" id="{$form[type].name}_1" name="{$form[type].name}_1" data-placeholder="{$form[type].placeholder}" {$form[type].extra_attr|default=''} data-ajax_url="{$form[type]['ajax_url']}" style="width: auto; display: inline-block">
            <option value="">{$form[type].placeholder}</option>
            {volist name="levelOne" id="option"}
            <option value="{$option[$form[type]['key']]}" {if (isset($levelKey[1]) && $levelKey[1] == (string)$option[$form[type]['key']])}selected{/if}>{$option[$form[type]['option']]|raw}</option>
            {/volist}
        </select>
        {eq name="form[type].level" value="2"}
        <select class="form-control" id="{$form[type].name}_2" name="{$form[type].name}" data-placeholder="{$form[type].placeholder}" {$form[type].extra_attr|default=''} style="width: auto; display: inline-block">
            <option value="">{$form[type].placeholder}</option>
            {notempty name="levelData.1"}
            {volist name="levelData.1" id="option"}
            <option value="{$option[$form[type]['key']]}" {if (isset($levelKey[2]) && $levelKey[2] == (string)$option[$form[type]['key']])}selected{/if}>{$option[$form[type]['option']]|raw}</option>
            {/volist}
            {/notempty}
        </select>
        {/eq}
        {eq name="form[type].level" value="3"}
        <select class="form-control js_linkage" data-model="{$form[type]['model']}" data-key="{$form[type]['key']}" data-key_value="{$form[type]['option']}" data-pid_field_name="{$form[type].pid|default='pid'}" data-next_level_id="{$form[type].name}_3" id="{$form[type].name}_2" name="{$form[type].name}_2" data-placeholder="{$form[type].placeholder}" {$form[type].extra_attr|default=''} data-ajax_url="{$form[type]['ajax_url']}" style="width: auto; display: inline-block">
            <option value="">{$form[type].placeholder}</option>
            {notempty name="levelData.1"}
            {volist name="levelData.1" id="option"}
            <option value="{$option[$form[type]['key']]}" {if (isset($levelKey[2]) && $levelKey[2] == (string)$option[$form[type]['key']])}selected{/if}>{$option[$form[type]['option']]|raw}</option>
            {/volist}
            {/notempty}
        </select>
        <select class="form-control" id="{$form[type].name}_3" name="{$form[type].name}" data-placeholder="{$form[type].placeholder}" {$form[type].extra_attr|default=''} style="width: auto; display: inline-block">
            <option value="">{$form[type].placeholder}</option>
            {notempty name="levelData.2"}
            {volist name="levelData.2" id="option"}
            <option value="{$option[$form[type]['key']]}" {if ($form[type].value == (string)$option[$form[type]['key']])}selected{/if}>{$option[$form[type]['option']]|raw}</option>
            {/volist}
            {/notempty}
        </select>
        {/eq}
    </div>
    {notempty name="form[type].tips"}
    <div class="col-12 offset-sm-2 offset-md-2 offset-lg-0 offset-xl-0 col-sm-10 col-md-10 col-lg-2 col-xl-4 dd_ts">
        <small class="text-muted">
            <i class="fa fa-info-circle"></i> {$form[type].tips|raw}
        </small>
    </div>
    {/notempty}
</div>